#include "mainwindowimpl.h"
#include "pm_init.h"
#include "optionsdialogimpl.h"
#include "mainapp.h"


#include <QMessageBox>
//
MainWindowImpl::MainWindowImpl ( QWidget * parent, Qt::WFlags f )
		: QMainWindow ( parent, f ) {
	setupUi ( this );
	ApplicationInit();
}
//

void MainWindowImpl::ApplicationInit() {
	this->setWindowTitle ( tr ( "Portage Manager %1" )
						   .arg ( PM_VERSION ) );


	m_centralAppList = new portageListImpl ( this );
	setCentralWidget ( m_centralAppList );
	m_centralAppList->setObjectName ( QString::fromUtf8 ( "centralAppList" ) );


	// check categories
	QListWidgetItem *item = new QListWidgetItem ( categoriesListWidget );
	item->setText ( MainApp::allText() );

	foreach ( QString line, MainApp::getCategories() ) {
		item = new QListWidgetItem ( categoriesListWidget );
		item->setText ( line );
	}

	connect ( categoriesListWidget, SIGNAL ( itemClicked ( QListWidgetItem* ) ), m_centralAppList, SLOT ( listCategory ( QListWidgetItem* ) ) );
}


void MainWindowImpl::on_action_Exit_triggered() {
	close();
}

void MainWindowImpl::on_action_Options_triggered() {
	MainOptions *opt = MainApp::app->getOptions();
	OptionsDialogImpl od ( opt );
	od.setParent ( this, Qt::Dialog );
	connect ( &od, SIGNAL ( saveall() ), opt, SLOT ( Save() ) );
	od.exec();
}



void MainWindowImpl::on_actionCategories_triggered ( bool checked ) {
	categoriesDockWidget->setVisible ( checked );
}

void MainWindowImpl::on_categoriesDockWidget_visibilityChanged ( bool visible ) {
	actionCategories->setChecked ( visible );
}



//void MainWindowImpl::on_categoriesListWidget_itemClicked ( QListWidgetItem* item ) {
//	m_centralAppList->listCategory ( item );
//}

